package com.wuhan.template.module.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.home.activity.DianBoItemActivity;
import com.wuhan.template.module.home.activity.WebVideoActivity;
import com.wuhan.template.module.home.entity.DianBoItemEntity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/16 0016.
 */
public class DianBoItemBaseAdapter extends MyBaseAdapter<DianBoItemEntity> {

    private Context context;
    private ImageLoader loader;
    private DisplayImageOptions options;
    List<DianBoItemActivity> list;

    public DianBoItemBaseAdapter(Context context, List<DianBoItemEntity> list) {
        super(context, list);
        this.context = context;
        loader = ((BaseApplication) (context.getApplicationContext())).getImageLoader();
        options = new DisplayImageOptions.Builder()
                .cacheInMemory(true).cacheOnDisk(true).build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.home_activity_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        return new ViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {
        ViewHolder holder = (ViewHolder) viewHolder;
        final DianBoItemEntity item = getItem(holder.position);
        holder.homeTitle.setText(item.getTitle());
        String url = item.getIndexpic().getHost() + item.getIndexpic().getDir() + item.getIndexpic().getFilepath() + item.getIndexpic().getFilename();
        loader.displayImage(url,holder.homeImage,options);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebVideoActivity.class);
                intent.putExtra("video",item.getContent_url());
                context.startActivity(intent);
            }
        });
    }

    public static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.home_itemImage)
        ImageView homeImage;
        @BindView(R.id.home_itemTitle)
        TextView homeTitle;
    }}
